<template>
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>首页信息管理</el-breadcrumb-item>
    <el-breadcrumb-item>学校信息修改</el-breadcrumb-item>
  </el-breadcrumb>


    <el-card>
      <!-- 搜索与添加区域 -->


      <!-- 用户列表区域 -->
      <el-form data="editschoolInfoForm" :model="editschoolInfoForm" border stripe >
        <el-form-item label="学校简介" prop="profile"><el-input v-model="editschoolInfoForm.profile" ></el-input></el-form-item>
        <el-form-item label="学校历史" prop="history"><el-input v-model="editschoolInfoForm.history" ></el-input></el-form-item>
        <el-form-item label="教学理念" prop="concept"><el-input v-model="editschoolInfoForm.concept" ></el-input></el-form-item>
        <el-form-item label="校园介绍" prop="introduce"><el-input v-model="editschoolInfoForm.introduce" ></el-input></el-form-item>
        <el-form-item label="校园风光" prop="url"><el-image :src="editschoolInfoForm.url" fit='fill' ></el-image></el-form-item>
        <el-form-item  prop="file"><input type="file"  @change="getFile($event)"/></el-form-item>
      </el-form>

      <el-row :gutter="20" >
        <el-col :span="4" >
          <el-button type="primary" @click="editschoolInfo">修改信息</el-button>
        </el-col>
      </el-row>

    </el-card>

</div>

</template>

<script>
  export default {
    data () {
      return {
      	editschoolInfoForm:{
      		id:'0',
      		profile:'',
          history:'',
          concept:'',
          introduce:'',
          file:''
      	}
      }
    },
    created() {
            this.getschoolInfoForm()
        },
      methods: {
            async getschoolInfoForm() {
                const { data: res } = await this.$http.get('introduce/'+0)
               
                if (res.code !== 200) {
                    return this.$message.error(res.msg)
                }
                this.editschoolInfoForm = res.data
                console.log(this.editschoolInfoForm )
            },
            // 修改用户信息并提交
            async editschoolInfo() {
            	let form = new FormData()
            	form.append('introduce',this.editschoolInfoForm.introduce)
            	form.append('profile',this.editschoolInfoForm.profile)
            	form.append('history',this.editschoolInfoForm.history)
            	form.append('concept',this.editschoolInfoForm.concept)
            	form.append('id',this.editschoolInfoForm.id)
            	form.append('file',this.editschoolInfoForm.file)
                    const { data: res } = await this.$http.put( 'introduce',form,{
                            headers:{
                                'Content-Type':'multipart/form-data'
                            }
                        })

               if (res.code !== 200) {
                  return this.$message.error(res.msg)
              }
                    // 刷新数据列表
                    this.getschoolInfoForm()
                    // 提示修改成功
                    this.$message.success('更新首页信息成功！')
                
            },
            getFile(event){
                this.editschoolInfoForm.file = event.target.files[0]
                console.log(this.editschoolInfoForm.file)
            }
        }
    }
 
</script>

<style>
</style>
